package com.nmc.service.dao.impl;


import java.util.List;

import org.hibernate.SessionFactory;

import com.nmc.service.dao.CommentsDao;
import com.nmc.service.model.Comments;

/**
 * This class interacts with Spring's HibernateTemplate to save/delete and
 * retrieve Comments objects.
 *
*/
public class CommentsDaoImpl extends GenericDaoImpl<Comments, Long> implements CommentsDao {

    public CommentsDaoImpl(Class<Comments> persistentClass,
			SessionFactory sessionFactory) {
		super(persistentClass, sessionFactory);
		// TODO Auto-generated constructor stub
	}

	public CommentsDaoImpl(Class<Comments> persistentClass) {
		super(persistentClass);
		// TODO Auto-generated constructor stub
	}

	/**
     * Constructor that sets the entity to User.class.
     */
    public CommentsDaoImpl() {
        super(Comments.class);
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public List<Comments> getCommentsList() {
        return getHibernateTemplate().find("from Comments u order by u.id");
    }

    /**
     * {@inheritDoc}
     */
    public Comments saveComments(Comments zones) {
        if (log.isDebugEnabled()) {
            log.debug("zones's id: " + zones.getId());
        }
        getHibernateTemplate().saveOrUpdate(zones);
        // necessary to throw a DataIntegrityViolation and catch it in UserManager
        getHibernateTemplate().flush();
        return zones;
    }

    /**
     * Overridden simply to call the saveComments method. This is happenening 
     * because saveComments flushes the session and saveObject of BaseDaoHibernate 
     * does not.
     *
     * @param zones obj to save
     * @return the modified zones (with a primary key set if they're new)
     */
    @Override
    public Comments save(Comments zones) {
        return this.saveComments(zones);
    }




    
}
